	@echo off
@REM  ----------------------------------------------------------------------------
@REM  CopyAssemblies.bat file
@REM
@REM  This batch file copies the Enterprise Library Extensions assemblies from 
@REM  their build location to a common destination folder.
@REM  
@REM  Optional arguments for this batch file:
@REM   1 - The build output folder (Release, Debug, etc. Defaults to Debug)
@REM   2 - The destination folder (i.e. where the build will be dropped.
@REM       Defaults to ..\bin)
@REM  
@REM  ----------------------------------------------------------------------------

echo.
echo =========================================================
echo   CopyAssemblies                                         
echo      Copies EnterpriseLibrary Extensions assemblies to 
echo      a single destination directory                              
echo =========================================================
echo.

set solutionDir="..\Blocks"
set buildType=Debug
set binDir="..\bin"
set pause=true

if "%1"=="/?" goto HELP

if not Exist %solutionDir%\EntLibEx.sln goto HELP

@REM  ----------------------------------------------------
@REM  If the first parameter is /q, do not pause
@REM  at the end of execution.
@REM  ----------------------------------------------------

if /i "%1"=="/q" (
 set pause=false
 SHIFT
)

@REM  ------------------------------------------------------
@REM  User can override default build type by specifiying
@REM  a parameter to batch file (e.g. CopyAssemblies Release).
@REM  ------------------------------------------------------

if not "%1"=="" set buildType=%1

@REM  ---------------------------------------------------------------
@REM  User can override default destination directory by specifiying
@REM  a parameter to batch file (e.g. CopyAssemblies Debug c:\bin).
@REM  ---------------------------------------------------------------

if not "%2"=="" set binDir=%2

@REM  ----------------------------------------
@REM  Shorten the command prompt for output
@REM  ----------------------------------------
set savedPrompt=%prompt%
set prompt=*$g


@ECHO ----------------------------------------
@ECHO CopyAssemblies.bat Started
@ECHO ----------------------------------------
@ECHO.

@REM -------------------------------------------------------
@REM Change to the directory where the solution file resides
@REM -------------------------------------------------------

pushd %solutionDir%

@ECHO.
@ECHO ----------------------------------------
@ECHO Create destination folder 
@ECHO ----------------------------------------
@ECHO.

if not Exist %binDir% mkdir %binDir%

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Policy Injection files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\PolicyInjection\Src\UnityBridge\bin\%buildType%\EnterpriseLibraryExtensions.PolicyInjection.UnityBridge.dll copy /V ..\Blocks\PolicyInjection\Src\UnityBridge\bin\%buildType%\EnterpriseLibraryExtensions.PolicyInjection.UnityBridge.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\PolicyInjection\Src\UnityBridge\bin\%buildType%\EnterpriseLibraryExtensions.PolicyInjection.UnityBridge.xml copy /V ..\Blocks\PolicyInjection\Src\UnityBridge\bin\%buildType%\EnterpriseLibraryExtensions.PolicyInjection.UnityBridge.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Unity Service Model files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Unity\Src\UnityServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Unity.ServiceModel.dll copy /V ..\Blocks\Unity\Src\UnityServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Unity.ServiceModel.dll %binDir%\.
@if errorlevel 1 goto :m
if Exist ..\Blocks\Unity\Src\UnityServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Unity.ServiceModel.xml copy /V ..\Blocks\Unity\Src\UnityServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Unity.ServiceModel.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Events files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Events\Src\EventHandling\bin\%buildType%\EnterpriseLibraryExtensions.Events.dll copy /V ..\Blocks\Events\Src\EventHandling\bin\%buildType%\EnterpriseLibraryExtensions.Events.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Events\Src\EventHandling\bin\%buildType%\EnterpriseLibraryExtensions.Events.xml copy /V ..\Blocks\Events\Src\EventHandling\bin\%buildType%\EnterpriseLibraryExtensions.Events.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Events ServiceModel files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Events\Src\Events.ServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Events.ServiceModel.dll copy /V ..\Blocks\Events\Src\Events.ServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Events.ServiceModel.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Events\Src\Events.ServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Events.ServiceModel.xml copy /V ..\Blocks\Events\Src\Events.ServiceModel\bin\%buildType%\EnterpriseLibraryExtensions.Events.ServiceModel.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Events Translation files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Events\Src\EnterpriseLibraryExtensions.Events.Translation\bin\%buildType%\EnterpriseLibraryExtensions.Events.Translation.dll copy /V ..\Blocks\Events\Src\EnterpriseLibraryExtensions.Events.Translation\bin\%buildType%\EnterpriseLibraryExtensions.Events.Translation.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Events\Src\EnterpriseLibraryExtensions.Events.Translation\bin\%buildType%\EnterpriseLibraryExtensions.Events.Translation.xml copy /V ..\Blocks\Events\Src\EnterpriseLibraryExtensions.Events.Translation\bin\%buildType%\EnterpriseLibraryExtensions.Events.Translation.xml %binDir%\.
@if errorlevel 1 goto :error


@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Services files
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Services\Src\EnterpriseLibraryExtensions.Services\bin\%buildType%\EnterpriseLibraryExtensions.Services.dll copy /V ..\Blocks\Services\Src\EnterpriseLibraryExtensions.Services\bin\%buildType%\EnterpriseLibraryExtensions.Services.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Services\Src\EnterpriseLibraryExtensions.Services\bin\%buildType%\EnterpriseLibraryExtensions.Services.xml copy /V ..\Blocks\Services\Src\EnterpriseLibraryExtensions.Services\bin\%buildType%\EnterpriseLibraryExtensions.Services.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO CopyAssemblies.bat Completed
@ECHO ----------------------------------------
@ECHO.

@REM  ----------------------------------------
@REM  Restore the command prompt and exit
@REM  ----------------------------------------
@goto :exit

@REM  -------------------------------------------
@REM  Handle errors
@REM
@REM  Use the following after any call to exit
@REM  and return an error code when errors occur
@REM
@REM  if errorlevel 1 goto :error	
@REM  -------------------------------------------
:error
  @ECHO An error occured in CopyAssemblies.bat - %errorLevel%

if %pause%==true PAUSE
@exit errorLevel

:HELP
echo Usage: CopyAssemblies [/q] [build output folder] [destination dir]
echo.
echo CopyAssemblies is to be executed in the directory where EnterpriseLibrary.sln resides
echo The default build output folder is Debug
echo The default destintation directory is bin
echo.
echo Examples:
echo.
echo    "CopyAssemblies" - copies Debug build assemblies to bin      
echo    "CopyAssemblies Release" - copies Release build assemblies to bin
echo    "CopyAssemblies Release C:\temp" - copies Release build assemblies to C:\temp
echo.

@REM  ----------------------------------------
@REM  The exit label
@REM  ----------------------------------------
:exit
popd
set pause=
set solutionDir=
set buildType=
set prompt=%savedPrompt%
set savedPrompt=
echo on
